#pragma once

#include "TListDlg.h"
#include "MsgMng.h"
#include "THosts.h"
#include "LogMng.h"


class TRecvDlg : public TListDlg {
protected:
	static int	createCnt;
	MsgMng		*msgMng;
	MsgBuf		msg;
	THosts		*hosts;
	char		head[MAX_LISTBUF];
	Cfg			*cfg;
	LogMng		*logmng;
	BOOL		openFlg;
	SYSTEMTIME	recvTime;
	HFONT		hHeadFont;
	HFONT		hEditFont;
	LOGFONT		orgFont;
	TEditSub	editSub;
	BOOL		status;

	RecvFileObj	*fileObj;
	ShareInfo	*shareInfo;

	UINT		timerID;
	UINT		retryCnt;
	char		readMsgBuf[MAX_LISTBUF];
	ULONG		packetNo;
	int			cryptCapa;

	RECT	orgRect;
	enum	recv_item { title_item=0, head_item, head2_item, open_item, edit_item, ok_item, cancel_item, quote_item, file_item, max_recvitem };
	WINPOS	item[max_recvitem];

	void	SetFont(void);
	void	SetSize(void);
	void	SetMainMenu(HMENU hMenu);
	void	PopupContextMenu(POINTS pos);
	BOOL	TcpEvent(SOCKET sd, LPARAM lParam);
	BOOL	StartRecvFile(void);
	BOOL	ConnectRecvFile(void);
	static DWORD WINAPI RecvFileThread(void *_recvDlg);
	BOOL	SaveFile(void);
	BOOL	OpenRecvFile(void);
	BOOL	RecvFile(void);
	BOOL	RecvDirFile(void);
	BOOL	CloseRecvFile(BOOL setAttr=FALSE);
	BOOL	EndRecvFile(BOOL manual_suspend=FALSE);
	void	SetTransferButtonText(void);
	BOOL	DecryptMsg(void);

public:
	TRecvDlg(MsgMng *_msgmng, MsgBuf *_msg, THosts *hosts, Cfg *cfg, LogMng *logmng);
	virtual ~TRecvDlg();

	virtual BOOL	IsClosable(void) { return openFlg && (fileObj == NULL || fileObj->conInfo == NULL); }
	virtual BOOL	IsSamePacket(MsgBuf *test_msg);
	virtual BOOL	SendFinishNotify(HostSub *hostSub, ULONG packet_no);

	virtual BOOL	EvCreate(LPARAM lParam);
	virtual BOOL	EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl);
	virtual BOOL	EvSysCommand(WPARAM uCmdType, POINTS pos);
	virtual BOOL	EvSize(UINT fwSizeType, WORD nWidth, WORD nHeight);
	virtual BOOL	EvGetMinMaxInfo(MINMAXINFO *info);
	virtual BOOL	EvTimer(WPARAM timerID, TIMERPROC proc);
	virtual BOOL	EvContextMenu(HWND childWnd, POINTS pos);
	virtual BOOL	EventButton(UINT uMsg, int nHitTest, POINTS pos);
	virtual BOOL	EventUser(UINT uMsg, WPARAM wParam, LPARAM lParam);
	virtual BOOL	EventInitMenu(UINT uMsg, HMENU hMenu, UINT uPos, BOOL fSystemMenu);
	virtual BOOL	EventCtlColor(UINT uMsg, HDC hDcCtl, HWND hWndCtl, HBRUSH *result);
	virtual void	Show(int mode = SW_NORMAL);
	BOOL			Status() { return status; }
	static int		GetCreateCnt(void) { return createCnt; }
};
